package job.manager.db.sb;

import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import job.manager.db.dao.JobDAO;
import job.manager.db.ec.JobEB;
import job.manager.db.ec.ProfilesEB;

/**
 *  SessionBean is the top layer and the main access point for handling the communcation
 *  from other modules to the database.
 *  This Bean is handling all the job requests.
 * 
 */
@Stateless
public class JobBean implements JobRemote, JobLocal {
      @PersistenceContext
        EntityManager em;

    public Collection<ProfilesEB> getWorkers(Integer jobId) {
        JobDAO dao=new JobDAO(em);
        return dao.getWorkers(jobId);
    }

    public JobEB getJob(Integer parameter) {
        return new JobDAO(em).getJob(parameter);
    }

    public Collection<JobEB> getJobsByProfile(ProfilesEB profile)
    {
        return new JobDAO(em).getJobsByCustomer(profile);
    }
    public Collection<JobEB> getJobsByProfile(Integer profileId)
    {
        return this.getJobsByProfile(em.find(ProfilesEB.class, profileId));
    }

    public Collection<JobEB> getAllJobs()
    {
        return new JobDAO(em).getAllJobs();
    }

    public JobEB insert(JobEB job)
    {
        return new JobDAO(em).insert(job);
    }

    public int update(JobEB job)
    {
        return new JobDAO(em).update(job);
    }

    public int delete(JobEB job)
    {
        return new JobDAO(em).delete(job);
    }

}
